home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 8 / Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO / 034a / aecur101.arj / CONTRIB / CURSES / INC / CURSES.H < prev    next >
C/C++ Source or Header  |  1991-12-02  |  9KB  |  259 lines

  1. /*----------------------------------------------------------------------
  2.  *
  3.  *  curses.h
  4.  *
  5.  *  copyright (c) 1987,88,89,90 J. Alan Eldridge
  6.  *
  7.  *  header file for Curses!
  8.  *
  9.  *  correspondence to:
  10.  *
  11.  * J. Alan Eldridge
  12.  * Liberty Brokerage
  13.  * 77 Water St.
  14.  * New York, NY 10005
  15.  * 
  16.  *----------------------------------------------------------------------
  17.  */
  18.  
  19. #ifndef __CURSES__
  20.  
  21. #define __CURSES__
  22.  
  23. #define CURSES_MAJOR_VERSION 3
  24. #define CURSES_MINOR_VERSION 0
  25.  
  26. #ifndef __GNUC__
  27.  
  28. /*
  29.     get the compiler header files we need
  30. */
  31.     
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <ctype.h>
  36. #include <limits.h>
  37.  
  38. #include "compiler.h"   /* define compilation environment */
  39.  
  40. #ifndef __UCHAR_DEFINED__
  41. #define __UCHAR_DEFINED__   1
  42. typedef unsigned char   UCHAR;  /* because I use it a lot */
  43. typedef signed char     SCHAR;  /* because we have UCHAR */
  44. #endif  /* __UCHAR_DEFINED__ */
  45.  
  46. #else
  47.  
  48. #include    "aedef.h"
  49. #include    <pc.h>
  50.  
  51. #define far
  52.  
  53. #endif
  54.  
  55. typedef struct {
  56.     UCHAR   chr,    /* each character in the PC video buffer ... */
  57.             att;    /* ... is represented by a char, attribute pair */
  58. } VIDCHR;
  59.  
  60. struct curses_v3_window;    /* create the name so I can typedef */
  61.  
  62. typedef struct curses_v3_window WINDOW; /* use WINDOW from now on */
  63.  
  64. struct curses_v3_window {
  65.     int     cury, curx,     /* logical cursor position */
  66.             maxy, maxx,     /* lower right hand corner */
  67.             orgy, orgx,     /* upper left hand corner */
  68.             attrib,         /* current video attribute */
  69.             s_attr,         /* "standout" video attribute */
  70.             n_attr,         /* "normal" video attribute */
  71.             b_attr,         /* "bright" video attribute */
  72.             flags,          /* see below for values */
  73.             firsty,         /* first line not updated on screen */
  74.             lasty,          /* last line not updated on screen */
  75.             *firstx,        /* array of ints: first x on line not updated */
  76.             *lastx;         /* array of ints: last x on line not updated */
  77.     VIDCHR  **buf;          /* array of ptrs to screen buffer, 1 per line */
  78.     UCHAR   appl_info[4];   /* for application use */
  79.     WINDOW  *next,          /* in case I want to link windows ... */
  80.             *prev;          /* ... in some kind of front-to-back list */
  81.     UCHAR   reserved[16];   /* in case I need something internally ... */
  82. };
  83.  
  84. /*
  85.     miscellaneous structures
  86. */
  87.     
  88. typedef struct {
  89.     UCHAR   model;
  90.     UCHAR   submodel;
  91. }   MACHINE_ID;
  92.  
  93. typedef union {
  94.     unsigned long       longval;
  95.     void far            *farptr;
  96.     struct {
  97.         short   offs;
  98.         short   seg;
  99.     }                   segoffs;
  100. }   FAR_PTR_UNION;    
  101.  
  102. /*
  103.     these are the rest of the Curses! include files
  104. */
  105.     
  106. #include "pckeybd.h"
  107. #include "pcvideo.h"
  108. #include "pmenuobj.h"
  109.  
  110. #include "curses.pro"
  111.  
  112. /* 
  113.     global variables
  114. */
  115.     
  116. extern  WINDOW  *stdscr,        /* default window */
  117.                 *curscr;        /* screen image window */
  118.  
  119. extern  int     LINES,          /* # rows on physical screen */
  120.                 COLS,           /* # cols on physical screen */
  121.                 __USE_BIOS,     /* use video BIOS calls? */
  122.                 __DEFNORM,      /* default "normal" attribute */
  123.                 __DEFSTAND,     /* default "standout" attribute */
  124.                 __DEFBRIGHT,    /* default "bright" attribute */
  125.                 __VIDMODE;      /* current video mode from BIOS */
  126.                 
  127. extern MACHINE_ID       __MACHID;   /* machine ID from ROM */
  128.  
  129. extern FAR_PTR_UNION    __VIDADDR;  /* far ptr to video RAM */
  130.  
  131. /*
  132.     miscellaneous constants 
  133. */
  134.  
  135. #define TRUE    1
  136. #define FALSE   0
  137.  
  138. #define OK      0
  139. #define ERR     -1
  140.  
  141. /*
  142.     values for WINDOW.flags bits
  143. */
  144.     
  145. #define _WCLEAR     0x0001
  146. #define _WLEAVE     0x0002
  147. #define _WSCROLL    0x0004
  148. #define _WWRAP      0x0008
  149. #define _WSUBWIN    0x0010
  150. #define _WFULLWIN   0x0020
  151. #define _WBOX       0x0040
  152. #define _WDIRTY     0x0080
  153.  
  154. /*
  155.     macro to determine the # of elements in an array
  156. */
  157.  
  158. #define NUM_ARRAY_ELEMS(arr)    (sizeof(arr)/sizeof((arr)[0]))
  159.  
  160. /*---------------------------------------------------------------------
  161.  *
  162.  *    macros that look like functions
  163.  *
  164.  *---------------------------------------------------------------------
  165.  */
  166.     
  167. /* these macros use internal function calls */
  168.  
  169. #define flushinp()          while(_kb_look())_kb_read()
  170. #define scroll(w)           _scroll((w),0,getmaxr(w),1)
  171. #define scrollwin(w,l)      _scroll((w),0,getmaxr(w),l)
  172. #define wdeleteln(w)        _scroll((w),(w)->cury,getmaxr(w),1)
  173. #define winsertln(w)        _scroll((w),(w)->cury,getmaxr(w),-1)
  174.  
  175. /* these macros are abbreviations for longer calling sequences */
  176.  
  177. #define addch(c)            waddch(stdscr,c)
  178. #define addstr(s)           waddstr(stdscr,s)
  179. #define beep()              putchar(7)           
  180. #define brightoff()         wbrightoff(stdscr)
  181. #define brighton()          wbrighton(stdscr)
  182. #define blinkoff()          wblinkoff(stdscr)
  183. #define blinkon()           wblinkon(stdscr)
  184. #define centstr(r,s)        wcentstr(stdscr,r,s)
  185. #define clear()             wclear(stdscr)
  186. #define clrtobot()          wclrtobot(stdscr)
  187. #define clrtoeol()          wclrtoeol(stdscr)
  188. #define delch()             wdelch(stdscr)
  189. #define deleteln()          wdeleteln(stdscr)
  190. #define editfld(b,n,t,i,s,f,z)      weditfld(stdscr,b,n,t,i,s,f,z)
  191. #define edittxt(b,n,t,i,s,f,z,p)    wedittxt(stdscr,b,n,t,i,s,f,z,p)
  192. #define egetstr(b)          wegetstr(stdscr,b)
  193. #define erase()             werase(stdscr)
  194. #define getch()             wgetch(stdscr)
  195. #define getstr(s)           wgetstr(stdscr,s)
  196. #define getattr(win)        ((win)->attrib & 0xff)
  197. #define getbright(win)      ((win)->b_attr & 0xff)
  198. #define getnorm(win)        ((win)->n_attr & 0xff)
  199. #define getorg(win,y,x)     ((y)=getorgy(win),(x)=getorgx(win))
  200. #define getorgx(win)        ((win)->orgx)
  201. #define getorgy(win)        ((win)->orgy)
  202. #define getmaxc(win)        ((win)->maxx)
  203. #define getmaxr(win)        ((win)->maxy)
  204. #define getmaxrc(win,r,c)   ((r)=getmaxr(win),(c)=getmaxc(win))
  205. #define getstand(win)       ((win)->s_attr & 0xff)
  206. #define getyx(win,y,x)      ((y)=(win)->cury,(x)=(win)->curx)
  207. #define hasbox(win)         ((win)->flags & _WBOX)
  208. #define inat()              winat(stdscr)
  209. #define inch()              winch(stdscr)
  210. #define insch(c)            winsch(stdscr, c)
  211. #define insertln()          winsertln(stdscr)
  212. #define iscolor()           (__VIDMODE != VID_MONO_80x25)
  213. #define move(r,c)           wmove(stdscr,r,c)
  214. #define mvaddch(r,c,ch)     (move(r,c),addch(ch))
  215. #define mvaddstr(r,c,str)   (move(r,c),addstr(str))
  216. #define mvcur(ly,lx,y,x)    vid_mov_curs(y,x)
  217. #define mvdelch(r,c)        (move(r,c),delch())
  218. #define mvdrawbox(win,r,c,y,x,v,h)      (wmove(win,r,c),drawbox(win,y,x,v,h))
  219. #define mveditfld(r,c,b,n,t,i,s,f,z)    (move(r,c),editfld(b,n,t,i,s,f,z))
  220. #define mveditstr(r,c,b,n)              (move(r,c),editstr(b,n))
  221. #define mvedittxt(r,c,b,n,t,i,s,f,z,p)  (move(r,c),editfld(b,n,t,i,s,f,z,p))
  222. #define mvegetstr(r,c,b)                (move(r,c),egetstr(b))
  223. #define mvgetch(r,c)        (move(r,c),getch())
  224. #define mvgetstr(r,c,s)     (move(r,c),getstr(s))
  225. #define mvinat(r,c)         (move(r,c),inat())
  226. #define mvinch(r,c)         (move(r,c),inch())
  227. #define mvinsch(r,c,ch)     (move(r,c),insch(ch))
  228. #define mvwaddch(win,r,c,ch)            (wmove(win,r,c),waddch(win,ch))
  229. #define mvwaddstr(win,r,c,s)            (wmove(win,r,c),waddstr(win,s))
  230. #define mvwdelch(win,r,c)               (wmove(win,r,c),wdelch(win))
  231. #define mvweditfld(w,r,c,b,n,t,i,s,f,z) (wmove(w,r,c),weditfld(w,b,n,t,i,s,f,z))
  232. #define mvweditstr(w,r,c,b,n)           (wmove(w,r,c),weditstr(w,b,n))
  233. #define mvwedittxt(w,r,c,b,n,t,i,s,f,z,p) \
  234.     (wmove(w,r,c),weditfld(w,b,n,t,i,s,f,z,p))
  235. #define mvwegetstr(w,r,c,b)     (wmove(w,r,c),wegetstr(w,b))
  236. #define mvwgetch(win,r,c)       (wmove(win,r,c),wgetch(win))
  237. #define mvwgetstr(win,r,c,s)    (wmove(win,r,c),wgetstr(win,s))
  238. #define mvwinat(win,r,c)        (wmove(win,r,c),winat(win))
  239. #define mvwinch(win,r,c)        (wmove(win,r,c),winch(win))
  240. #define mvwinsch(win,r,c,ch)    (wmove(win,r,c),winsch(win,ch))
  241. #define refresh()           wrefresh(stdscr)
  242. #define setattr(w,a)        ((w)->attrib = (a))
  243. #define setbright(w,a)      ((w)->b_attr = (a))
  244. #define setnorm(w,a)        ((w)->n_attr = (a))
  245. #define setstand(w,a)       ((w)->s_attr = (a))
  246. #define standend()          wstandend(stdscr)
  247. #define standout()          wstandout(stdscr)
  248. #define use_vid_bios(flag)  (__USE_BIOS=(flag))
  249. #define wblinkoff(win)      ((win)->attrib &= 0x7f)
  250. #define wblinkon(win)       ((win)->attrib |= 0x80)
  251. #define wbrightoff(win)     wstandend(win)
  252. #define wbrighton(win)      ((win)->attrib = (win)->b_attr)
  253. #define winat(win)          ((win)->buf[(win)->cury][(win)->curx].att)
  254. #define winch(win)          ((win)->buf[(win)->cury][(win)->curx].chr)
  255. #define wstandend(win)      ((win)->attrib = (win)->n_attr)
  256. #define wstandout(win)      ((win)->attrib = (win)->s_attr)
  257.  
  258. #endif  /* __CURSES */
  259.